<template>
	<div>
		<div class='place-foot'></div>
		<!--<div class='iphonex-bar' wx:if="{{isIPhoneX}}"></div>-->
		<div class='fixed-footer'>
			<div class='footer-content'>
				<span class='total-prices'>￥{{shoppingSelectGoods.goods_amount}}</span>
				<div :class='shoppingSelectGoods.is_paisong == "B" ? "gary" :"go-buy-btn"  ' @click='createOrder'>立即支付</div>
			</div>
			<!--<div class='iphonex-bar' wx:if="{{isIPhoneX}}"></div>-->
		</div>
	</div>
</template>

<script>
	import server from '@/server/api';
	import { mapGetters, mapState, mapMutations } from 'vuex';
	import { Toast, MessageBox } from 'mint-ui';
	export default {
		props: ["isUserWallet"],
		data() {
			return {
				orderDetailText: null
			}
		},
		mounted() {},
		computed: {
			...mapState(['shoppingSelectGoods'])
		},
		methods: {
			...mapMutations(['countDownTime']),
			createOrder() {
				//				this.$router.push("/payment");
				const _this = this;
				if(!lockClick(1000)) {
					console.log("一秒内点击两次！")
					return;
				}
				if(!_this.shoppingSelectGoods.address_info && _this.shoppingSelectGoods.address_info.address_id) {
					Toast("请先选择收货地址");
					return;
				}
				let param = {
					member_id: 101076,
					order_amount: _this.shoppingSelectGoods.order_amount,
					goods_amount: _this.shoppingSelectGoods.goods_amount,
					order_message: _this.shoppingSelectGoods.message ? _this.shoppingSelectGoods.message : "",
					address_id: _this.shoppingSelectGoods.address_info.address_id,
					spice: _this.shoppingSelectGoods.sprice
				};
				if(_this.shoppingSelectGoods.param.ifcart == 1) {
					param.ifcart = 1;
					param.cart_info = _this.shoppingSelectGoods.param.cart_info;
				} else {
					param.order_label = _this.shoppingSelectGoods.order_label;
					if(_this.shoppingSelectGoods.order_label == 1) {
						param.goods_id = _this.shoppingSelectGoods.goods_list[0].goods_id;
						let monthlist = _this.shoppingSelectGoods.goods_list[0].monthlist;
						for(var i = 0; i < _this.shoppingSelectGoods.goods_list[0].monthlist.length; i++) {
							monthlist[i].month_book_price = _this.shoppingSelectGoods.goods_list[0].goods_price
						}
						monthlist = JSON.stringify(monthlist);
						param.monthlist = monthlist;
						param.spec = _this.shoppingSelectGoods.goods_list[0].spec_name;
					} else if(_this.shoppingSelectGoods.order_label == 0) {
						let collocation_list = [];
						param.ifcart = "collocation";
						for(var i = 0; i < _this.shoppingSelectGoods.goods_list.length; i++) {
							collocation_list.push({
								goods_id: _this.shoppingSelectGoods.goods_list[i].goods_id,
								is_collocation: _this.shoppingSelectGoods.goods_list[i].is_collocation,
								num: _this.shoppingSelectGoods.goods_list[i].num,
								sp_value_id: _this.shoppingSelectGoods.goods_list[i].sp_value_id,
								sprice: _this.shoppingSelectGoods.goods_list[i].sprice,
							})
						}
						param.collocation_list = JSON.stringify(collocation_list);
					} else if(_this.shoppingSelectGoods.order_label == 2 || _this.shoppingSelectGoods.order_label == 3) {
						param.goods_id = _this.shoppingSelectGoods.goods_list[0].goods_id;
						param.num = _this.shoppingSelectGoods.goods_list[0].num;
						param.sp_value_id = _this.shoppingSelectGoods.goods_list[0].sp_value_id;
					}

				}
				server.post("/index/buy/buy_step2", param, function(res) {
				
					if(res.error != 0) {
						Toast(res.data.message);
						return;
					}
					//					_this.$store.state.paymentDetail = res.data;
					//					_this.$router.push("/payment");
					_this.toPay(res.data)
				})
			},
			toPay(orderInfo) {
				
				const _this = this;
				let param = {
					member_id: 101076,
					address_id: _this.shoppingSelectGoods.address_info.address_id,
					all_no: orderInfo.all_no,
					order_label: orderInfo.order_label,
					openid: "oGEpG4-UFfHoa_EXCuryj31Z20-Y"
				};
				if(_this.isUserWallet) {
					param.is_wallet = 2;
					MessageBox.confirm('确定执行此操作?').then(action => {
						_this.applyPay(param);
					});
					//					wx.showModal({
					//						title: '提示',
					//						content: '您将使用钱包支付',
					//						success: function(res) {
					//							if(res.confirm) {
					//								applyPay(param);
					//							} else {
					//								tool.warning("支付失败");
					//								wx.navigateTo({
					//									// url: '/pages/container/order-details/order-details?all_no=' + orderInfo.all_no+"&order_label="+ orderInfo.order_label,
					//									url: '/pages/container/order-details/goods-to-pay/goods-to-pay?all_no=' + orderInfo.all_no + "&order_label=" + orderInfo.order_label
					//								});
					//							}
					//						}
					//					});
				} else {
					param.is_wallet = 1;
					applyPay(param);
				}
			},
			applyPay(param) {
				const _this = this;
				server.post("/index/Wxpay/index", param, function(res) {
				
					if(res.error != 0) {
						Toast(res.message);
						return;
					}
					if(res.data.order_state == 20 || res.data.data.judge == 1) {
						Toast({
							message: '支付成功',
							iconClass: 'mint-toast-icon mintui mintui-success',
							duration:1000
						});
						setTimeout(function() {
							_this.$router.push("/order");
							//							wx.switchTab({
							//								// url: '/pages/container/order-details/order-details?all_no=' + param.all_no + "&order_label=" + param.order_label
							//								url: '/pages/container/order-list/order-list'
							//							});
						}, 1000);
						return;
					}
					_this.$store.state.paymentDetail = res.data;
					_this.$router.push("/payment");
				});
			}
		}
	}
</script>

<style scoped>
	.fixed-footer {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: #fff;
		box-shadow: -6px -6px 20px 0 rgba(69, 69, 83, 0.05);
	}
	
	.place-foot {
		height: 112px;
	}
	
	.footer-content {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 112px;
		padding: 0 40px;
	}
	
	.footer-content .total-prices {
		font-size: 42px;
		color: #454553;
	}
	
	.footer-content .go-buy-btn {
		height: 74px;
		padding: 0 20px;
		background-image: linear-gradient(-180deg, #F64565 0%, #EF364E 100%);
		text-align: center;
		line-height: 74px;
		color: #fff;
		font-size: 28px;
		box-shadow: 0 20px 20px 0 rgba(244, 63, 92, 0.15);
		border-radius: 8px;
	}
	
	.footer-content .gary {
		height: 74px;
		padding: 0 20px;
		background-color: #f8f8f8;
		text-align: center;
		line-height: 74px;
		color: #67666B;
		font-size: 28px;
		border-radius: 8px;
	}
</style>